package com.feng.demo.thread;

import java.io.Serializable;

public class ThreadPoolTask implements Runnable, Serializable {
	private static int consumeTaskSleepTime = 5*1000;
	private static final long serialVersionUID = 0;
	private static final String TASK_NAME = "pool-test-";
	private Object threadPoolTaskData;

	ThreadPoolTask(Object tasks) {
		this.threadPoolTaskData = tasks;
	}

	public void run() {
		synchronized (TASK_NAME) {
			
		// 处理一个任务，这里的处理方式太简单了，仅仅是一个打印语句
		System.out.println("begin>>>>>>>>" +Thread.currentThread().getName()+ threadPoolTaskData);
		try {
			// //便于观察，等待一段时间
			//Thread.currentThread().setName("pool-test-"+Thread.currentThread().getName());
			Thread.sleep(consumeTaskSleepTime);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("end<<<<<<<<<" +Thread.currentThread().getName()+ threadPoolTaskData);
		threadPoolTaskData = null;
		}
	}

	public Object getTask() {
		return this.threadPoolTaskData;
	}
}
